package com.heima.controller;

import com.heima.common.result.PageResult;
import com.heima.common.result.Result;
import com.heima.pojo.dto.PageDTO;
import com.heima.pojo.entity.Region;
import com.heima.pojo.vo.RegionPageVO;
import com.heima.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * \* User: chy
 * \* Date: 2025/8/17  13:03
 * \* Description:区域搜索模块
 * \
 */
@RestController
@RequestMapping("api/vm-service/region")
@Slf4j
public class RegionController {
    @Autowired
    private RegionService regionService;

    /**
     * 区域搜索分页查询
     * @param pageDTO
     * @return
     */
    @GetMapping("/search")
    public PageResult<RegionPageVO> page(PageDTO pageDTO){
        log.info("区域搜索分页查询{}",pageDTO);
        return regionService.page(pageDTO);
    }

    /**
     * 新增区域
     * @param region
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Region region){
        log.info("新增区域数据:{}",region);
        regionService.add(region);
        return Result.success();
    }

    /**
     * 修改区域
     * @param regionId
     * @param region
     * @return
     */

    @PutMapping("/{regionId}")
    public Result update(@PathVariable String regionId ,@RequestBody Region region){
        region.setId(regionId);
        log.info("修改区域数据:{}",region);
        regionService.updateById(region);
        return Result.success();
    }


    /**
     * 删除区域
     * @param regionId
     * @return
     */
    @DeleteMapping("/{regionId}")
    public Result deleteById(@PathVariable String regionId){
        log.info("删除区域id为:{}",regionId);
        regionService.deleteById(regionId);
        return Result.success();
    }
}
